import streamlit as st
from auth import get_current_user, is_logged_in
from ai_left_sidebar import render_secondary_navigation
from ai_right_main import render_main

def render_layout():
    """
    渲染两列布局，左侧为侧边栏，右侧为主界面，比例为 2:5
    """
    # 检查用户是否登录
    if is_logged_in():
        user = get_current_user()
        # 创建两列布局，比例为 2:5
        col1, col2 = st.columns([2, 5])

        # 在左侧列中渲染侧边栏并获取选中的对话 ID
        with col1:
            selected_conversation = render_secondary_navigation()

        # 如果 selected_conversation 为空，初始化一个新会话
        if not selected_conversation:
            st.session_state.is_new_conversation = True  # 标记为新会话模式
            selected_conversation = "new_conversation"  # 设置一个默认值

        # 在右侧列中渲染主界面
        with col2:
            render_main(selected_conversation)

# 调用渲染布局的函数
# render_layout()